/**
 * 版权所有(C)，上海勾芒信息科技，2016，所有权利保留。
 * 
 * 项目名：	carwx
 * 文件名：	OrderEventListener.java
 * 模块说明：	
 * 修改历史：
 * 2016年12月4日 - Debenson - 创建。
 */
package com.alex.insistence.web.event;

import org.jeecgframework.web.system.controller.core.UserLoginEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

import com.alex.wechat.component.account.entity.WxComponentAccountEntity;
import com.alex.wechat.component.account.service.WxComponentAccountServiceI;
import com.alex.wechat.component.config.WxComponentContext;
import com.alex.wechat.mp.account.entity.WxAccountEntity;
import com.alex.wechat.mp.account.service.WxAccountServiceI;
import com.alex.wechat.mp.config.WxContext;

/**
 * 用户登录后事件处理。
 * 
 * @author Debenson
 * @since 0.1
 */
@Service
public class UserLoginEventListener implements ApplicationListener<UserLoginEvent> {
  private static final Logger logger = LoggerFactory.getLogger(UserLoginEventListener.class);

  @Autowired
  private WxAccountServiceI accountService;
  @Autowired
  private WxComponentAccountServiceI compAccountService;

  @Override
  public void onApplicationEvent(UserLoginEvent event) {
    WxAccountEntity account = accountService.getWxAccountByLogin();
    logger.info("当前公众号={}", account == null ? null : account.getOriginalId());
    if (account != null) {
      WxContext.setOriginalId(account.getOriginalId());
    }

    WxComponentAccountEntity compAccount = compAccountService.getAccountByLogin();
    logger.info("当前第三方开发平台账号={}", compAccount == null ? null : compAccount.getAppId());
    if (compAccount != null) {
      WxComponentContext.setAppId(compAccount.getAppId());
    }
  }
}
